﻿using System;
using MaLu.Data;
using Malu.WebTemplates;
using Wicresoft.Framework.Organization;
using System.Configuration;

namespace MaLu.Common
{
    public class HPage : BaseAuthenticationPage
    {
        private IDbProvider provider = null;
        protected IDbProvider Provider
        {
            get
            {
                if (provider == null)
                {
                    provider = ProviderManager.Factory.CreateDbProvider();
                    provider.Open();
                   
                }
                return provider;
            }

        }
        public Guid DepartmentID
        {
            get
            {
                if (Request["DepartmentID"] != null)
                    return new Guid(Request["DepartmentID"]);
                if (ViewState["DepartmentID"] == null)
                    ViewState["DepartmentID"] = Guid.Empty;
                return (Guid)ViewState["DepartmentID"];
            }
            set
            {
                ViewState["DepartmentID"] = value;
            }
        }

        private int iriskadmin = -1;
        private bool isriskadmin = false;
        public bool IsRiskAdmin
        {
            get
            {
                if (iriskadmin == -1)
                {
                    isriskadmin = OrganizationHelper.IsUserInRole(CurrentUser.ID, new Guid(ConfigurationManager.AppSettings["HRiskAdmin"]));
                    iriskadmin = 0;
                }
                return isriskadmin;
            }
        
        }

        private int irisksubadmin = -1;
        private bool isrisksubadmin = false;
        public bool IsRiskSubAdmin
        {
            get
            {
                if (irisksubadmin == -1)
                {
                    isrisksubadmin = OrganizationHelper.IsUserInRole(CurrentUser.ID, new Guid(ConfigurationManager.AppSettings["HRiskSubAdmin"]));
                    irisksubadmin = 0;
                }
                return isrisksubadmin;
            }

        }
    }
}
